package com.example.mcpweather.tool;

import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.ai.tool.annotation.Tool;
import org.springframework.ai.tool.annotation.ToolParam;
import org.springframework.stereotype.Service;
@Service
@Slf4j
public class SearchNews {
    /**
     * 热点新闻获取工具
     * @return
     */
    @Tool(name="getNews",description = "获取热点新闻")
    public String getNews(@ToolParam(description = "数量",required = true) int num){
        String url="https://v3.alapi.cn/api/new/wbtop";
        String token="uuivnzcfbkr0tue9usf3tfjl6fbryj";
        //int num=5;
        log.info("获取热点新闻url = {}",url);
        log.info("获取热点新闻数量 = {}",num);
//        String response= HttpRequest.post(url+"?token="+token+"?num="+num)
//                .header("Content-Type", "application/x-www-form-urlencoded")
//                .toString();
//        return HttpUtil.post(url, "token="+token+"&num="+num);
        return HttpUtil.post(url, "token="+token+"&num="+num);
    }
}
